package com.huihui.springbootwebflux.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
public class TestController {

    @GetMapping("/get")
    public String get(){
        log.info("start");
        return getData();
    }

    @GetMapping("/get1")
    public Mono<String> get1(){
        log.info("start");
        Mono<String> mono = get2();
//        return mono;
        return Mono.just("hello1");
    }

    public Mono<String> get2(){
        Mono<String> mono = Mono.fromSupplier(() -> getData());
        return mono;
    }

    public String getData(){
        try {
            log.info("getData");
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "hello";
    }
}
